﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using MyVoteMVC.Common.Specifications;

namespace MyVoteMVC.Data.Repositories
{
    public interface IRepository
    {
    }

    /// <summary>
    /// 为每个表建立一个知识库
    /// </summary>
    /// <typeparam name="TEntity"></typeparam>
    public interface IRepository<TEntity> : IRepository where TEntity : class
    {
        IQueryable<TEntity> QueryableEntity();
       
        /// <summary>
        /// 获取整个实体集
        /// </summary>
        /// <returns></returns>
        IEnumerable<TEntity> GetAll();

        int GetAllCount();

        /// <summary>
        /// 获取整个实体集
        /// </summary>
        /// <typeparam name="TKey">用于排序的列</typeparam>
        /// <param name="orderby">排序lambda</param>
        /// <returns></returns>
        IEnumerable<TEntity> GetAll<TKey>(Expression<Func<TEntity, TKey>> orderby);

        /// <summary>
        /// 获取整个实体集
        /// </summary>
        /// <typeparam name="TKey">用于排序的列</typeparam>
        /// <param name="pageIndex">页数</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="orderby">排序lambda</param>
        /// <returns></returns>
        IEnumerable<TEntity> GetAll<TKey>(int pageIndex, int pageSize, Expression<Func<TEntity, TKey>> orderby, out int count);


        /// <summary>
        /// 获取一定条件下的实体集
        /// </summary>
        /// <param name="expression">lambda表达式：用于表示条件</param>
        /// <returns>实体集合</returns>
        IEnumerable<TEntity> GetMany(Expression<Func<TEntity, bool>> expression);

        int GetManyCount(Expression<Func<TEntity, bool>> expression);

        /// <summary>
        /// 获取一定条件下的实体集
        /// </summary>
        /// <typeparam name="TKey">用于排序的列</typeparam>
        /// <param name="expression">lambda表达式：用于表示条件</param>
        /// <param name="orderby">排序lambda</param>
        /// <returns></returns>
        IEnumerable<TEntity> GetMany<TKey>(Expression<Func<TEntity, bool>> expression, Expression<Func<TEntity, TKey>> orderby);
        /// <summary>
        /// 获取一定条件下的实体集
        /// </summary>
        /// <typeparam name="TKey">用于排序的列</typeparam>
        /// <param name="expression">lambda表达式：用于表示条件</param>
        /// <param name="pageIndex">页数</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="orderby">排序lambda</param>
        /// <returns></returns>
        IEnumerable<TEntity> GetMany<TKey>(Expression<Func<TEntity, bool>> expression, int pageIndex, int pageSize, Expression<Func<TEntity, TKey>> orderby, out int count);


        /// <summary>
        /// 获取一定条件下的实体集，支持条件组合
        /// </summary>
        /// <param name="specification">条件组合参数</param>
        /// <returns>实体集合</returns>
        IEnumerable<TEntity> GetMany(ISpecification<TEntity> specification);
        int GetManyCount(ISpecification<TEntity> specification);

        /// <summary>
        /// 获取一定条件下的实体集，支持条件组合
        /// </summary>
        /// <typeparam name="TKey">用于排序的列</typeparam>
        /// <param name="specification">条件组合参数</param>
        /// <returns></returns>
        IEnumerable<TEntity> GetMany<TKey>(ISpecification<TEntity> specification, Expression<Func<TEntity, TKey>> orderby);
        /// <summary>
        /// 获取一定条件下的实体集，支持条件组合
        /// </summary>
        /// <typeparam name="TKey"></typeparam>
        /// <param name="specification">条件组合参数</param>
        /// <param name="pageIndex">页数</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="orderby">排序lambda</param>
        /// <returns></returns>
        IEnumerable<TEntity> GetMany<TKey>(ISpecification<TEntity> specification, int pageIndex, int pageSize, Expression<Func<TEntity, TKey>> orderby, out int count);

        /// <summary>
        /// 获取符合单个主键的一个实体
        /// </summary>
        /// <param name="Id">主键值</param>
        /// <returns></returns>
        TEntity GetEntityById(string Id);

        /// <summary>
        /// 获取符合复合主键的一个实体
        /// </summary>
        /// <param name="values">复合主键值</param>
        /// <returns></returns>
        TEntity GetEntityById(params object[] values);

        /// <summary>
        /// 新增实体记录
        /// </summary>
        /// <param name="entity">需要新增的实体</param>
        /// <returns>是否新增成功</returns>
        bool Add(TEntity entity);

        /// <summary>
        /// 更新实体记录
        /// </summary>
        /// <param name="entity">需要更新的实体</param>
        /// <returns>是否更新成功</returns>
        bool Update(TEntity entity);

        /// <summary>
        /// 按主键值删除实体集中的实体
        /// </summary>
        /// <param name="Id">主键值</param>
        /// <returns>是否删除成功</returns>
        bool Delete(string Id);

        /// <summary>
        /// 删除实体
        /// </summary>
        /// <param name="entity">要删除的实体</param>
        /// <returns>是否删除成功</returns>
        bool Delete(TEntity entity);

        /// <summary>
        /// 删除多个实体
        /// </summary>
        /// <param name="entitys">要删除的实体集合</param>
        /// <returns>是否删除成功</returns>
        bool Delete(IEnumerable<TEntity> entitys);
    }

 
}
